package com.grace.service.impl;

import com.grace.entity.Permission;
import com.grace.entity.Role;
import com.grace.mapper.RoleMapper;
import com.grace.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;


    @Override
    public List<Role> findAll() {
        return roleMapper.findAll();
    }

    @Override
    public void save(Role role) {
        roleMapper.save(role);
    }

    @Override
    public Role findById(String roleId) {
        return roleMapper.findById(roleId);
    }

    @Override
    public List<Permission> findByRoleIdAndOtherPers(String roleId) {
        return roleMapper.findByRoleIdAndOtherPers(roleId);
    }

    @Override
    public void addPermissionToRole(String roleId, String[] perIds) {
        for (String perId : perIds) {
            roleMapper.addPermissionToRole(roleId, perId);
        }
    }

}
